#include "Plugin.h"
#include "PluginManager.h"
#include "ObjectManager.h"

ModuleInfo::ModuleInfo()
{
	pluginName = "";
	author = "";
	version = 0x00000001;
	commands = NULL;
	Count = 0;
}

int ModuleInfo::GetNumOfCommands()
{
	return Count;
}

void ModuleInfo::SetNumOfCommands(int NewNumber)
{
	if(NewNumber < 0)
		NewNumber = 0;
	Value *OldCommands = commands;
	commands = new Value [NewNumber];
	int Min = (Count < NewNumber) ? Count : NewNumber;
	for(int i = 0; i < Min; i++)
	{
		commands[i] = OldCommands[i]; 
	}
	Count = NewNumber;
}

PluginBase::PluginBase()
{
	m_ModuleInfo.pluginName = "BasePlugin";
	m_ModuleInfo.author = "Josh Anderson";
	m_ModuleInfo.version = 0x00000001; // 0xMMmmaabb   MM = Major mm = Minor aa = Macro bb = Build
	m_ModuleInfo.numOfCommands = 1;
	m_ModuleInfo.commands[0] = "BasicCommand";
}

void __stdcall PluginBase::Initialize(PluginManager *Parent, ObjectManager *Objects)
{ 
	m_Manager = Parent; 
	m_Objects = Objects;
}

void __stdcall PluginBase::Dispose()
{
}

void __stdcall PluginBase::DeleteThis()
{
}

ModuleInfo __stdcall PluginBase::GetModuleInfo()
{
	return m_ModuleInfo;
}

bool __stdcall PluginBase::HandleCommand(Command &newCommand)
{
	bool found = false;
	for(int i = 0; i < m_ModuleInfo.numOfCommands; i++)
	{
		if(m_ModuleInfo.commands[i] == newCommand.name)
		{
			found = true;
			break;
		}
	}
	if(found)
	{
		//Handle the command
		return true;
	}
	return false;
}